<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="74px">
      <el-form-item label="招标编号" prop="sectionId">
        <el-input v-model="queryParams.sectionId" placeholder="请输入招标编号" clearable @clear="handleQuery"  @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="招标名称" prop="sectionName">
        <el-input v-model="queryParams.sectionName" placeholder="请输入招标名称" clearable @clear="handleQuery"  @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="开标时间" prop="open">
        <el-date-picker clearable @clear="handleQuery" v-model="queryParams.open" type="date" value-format="yyyy-MM-dd" @change="handleQuery" placeholder="请选择开标时间"></el-date-picker>
      </el-form-item>
      <el-form-item label="招标进度" prop="sectionProgress">
        <el-select v-model="queryParams.sectionProgress" placeholder="请选择招标进度" clearable @clear="handleQuery" @change="handleQuery">
          <el-option
            v-for="dict in dict.type.section_progress"
            :key="dict.value"
            :label="dict.label"
            :value="Number(dict.value)">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" v-hasPermi="['system:reserve:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="sectionList" border>
      <el-table-column label="序号" type="index" fixed width="55" align="center" />
      <el-table-column label="部门" fixed align="center" prop="projectInfo.deptName" show-overflow-tooltip />
      <el-table-column label="项目负责人" fixed align="center" prop="projectInfo.assistant"  width="120" show-overflow-tooltip />
      <el-table-column label="招标编号" align="center" prop="sectionId"  width="120" show-overflow-tooltip>
        <template slot-scope="scope">
          <span @dblclick="copyText(scope.row.sectionId)">{{ scope.row.sectionId }}</span>
        </template>
      </el-table-column>
      <el-table-column label="招标名称" align="center" prop="sectionName"  width="180" show-overflow-tooltip>
        <template slot-scope="scope">
          <span @dblclick="copyText(scope.row.sectionName)">{{ scope.row.sectionName }}</span>
        </template>
      </el-table-column>
      <el-table-column label="组织方式" align="center"  width="180">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_bidmethos" :value="scope.row.bidmethod"/>
        </template>
      </el-table-column>
      <el-table-column label="招标类别" align="center" prop="qualify" width="100" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{ selectDictLabel(dict.type.sys_bidcategory, scope.row.projectInfo.bidcategory) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="开标时间" align="center" prop="open" width="180" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.open, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="招标进度" align="center" width="120" show-overflow-tooltip>
        <template slot-scope="scope">
          <el-tag :type="scope.row.sectionProgress === 8 || scope.row.sectionProgress === 9 ? 'danger' : (scope.row.sectionProgress === 7 ? 'success' : '' )">{{ selectDictLabel(dict.type.section_progress, scope.row.sectionProgress) }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="定标单位" align="center" width="140" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{ scope.row.winCompany }}</span>
        </template>
      </el-table-column>
      <el-table-column label="预定标金额" align="center" width="140" show-overflow-tooltip>
        <template slot-scope="scope">
          <span v-if="scope.row.preMoney">{{ scope.row.preMoney }} 元</span>
        </template>
      </el-table-column>
      <el-table-column label="预定标时间" align="center" prop="open" width="180" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.preDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="绩效确认时间" align="center" prop="open" width="180" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.meritDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="正式定标金额" align="center" width="140" show-overflow-tooltip>
        <template slot-scope="scope">
          <span v-if="scope.row.formalMoney">{{ scope.row.formalMoney }} 元</span>
        </template>
      </el-table-column>
      <el-table-column label="正式定标时间" align="center" prop="open" width="180" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.formalDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" fixed="right" width="220" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-folder-add"
            @click="handleOpenDialog(scope.row, 'reserve')"
            v-hasPermi="['system:reserve:expect']"
          >预定标</el-button>
          <!--  v-if="scope.row.sectionProgress >= 3" -->
          <el-button
            size="mini"
            type="text"
            icon="el-icon-folder-checked"
            @click="handleOpenDialog(scope.row, 'formal')"
            v-if="scope.row.sectionProgress >= 4"
            v-hasPermi="['system:reserve:formal']"
          >正式定标</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleDetail(scope.row)"
            v-hasPermi="['system:reserve:detail']"
          >查看</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 预定标对话框 -->
    <el-dialog class="section-dialog" :title="reserveTitle" :visible.sync="reserveOpen" width="50%" append-to-body>
      <el-card class="box-card" shadow="hover">
        <div slot="header" class="clearfix">
          <span>标段信息</span>
        </div>
        <el-form ref="reserveFormRef" :model="reserveForm" :rules="reserveFormRules" label-width="96px">
          <el-row>
            <el-col :span="11">
              <el-form-item label="招标编号" prop="sectionId">
                <el-input v-model="reserveForm.sectionId" disabled placeholder="请输入招标编号" />
              </el-form-item>
            </el-col>
            <el-col :span="11" :offset="1">
              <el-form-item label="招标名称" prop="sectionName">
                <el-input v-model="reserveForm.sectionName" disabled placeholder="请输入招标名称" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="11">
              <el-form-item label="估算价" prop="planprice">
                <el-input class="pirce" v-model="reserveForm.planprice" disabled placeholder="请输入估算价" /> 元
              </el-form-item>
            </el-col>
            <el-col :span="11" :offset="1">
              <el-form-item label="定标单位" prop="winCompany">
                <el-input v-model="reserveForm.winCompany" disabled placeholder="请输入定标单位" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="11">
              <el-form-item label="预定标金额" prop="preMoney">
                <el-input class="pirce" v-model="reserveForm.preMoney" disabled placeholder="请输入预定标金额" /> 元
              </el-form-item>
            </el-col>
            <el-col :span="11" :offset="1">
              <el-form-item label="预定标时间" prop="preDate">
                <el-date-picker clearable
                  v-model="reserveForm.preDate"
                  type="date"
                  format="yyyy-MM-dd"
                  value-format="yyyy-MM-dd"
                  placeholder="请选择预定标时间">
                </el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="11">
              <el-form-item label="绩效确认时间" prop="meritDate">
                <el-date-picker clearable
                  v-model="reserveForm.meritDate"
                  type="date"
                  format="yyyy-MM-dd"
                  value-format="yyyy-MM-dd"
                  placeholder="请选择绩效确认时间">
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="11" :offset="1">
              <el-form-item label="是否内部单位中标" title="是否内部单位中标" prop="inn">
                <el-radio-group v-model="reserveForm.inn">
                  <el-radio :label="Number(dict.value)" v-for="dict in dict.type.is_switch" :key="dict.value">{{ dict.label }}</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="11">
              <el-form-item label="是否统计节支率" title="是否统计节支率" prop="whetherSave">
                <el-radio-group v-model="reserveForm.whetherSave">
                  <el-radio :label="Number(dict.value)" v-for="dict in dict.type.is_switch" :key="dict.value">{{ dict.label }}</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </el-card>
      <el-card class="box-card" shadow="hover">
        <div slot="header" class="clearfix">
          <span>投标信息</span>
        </div>
        <el-table v-loading="tenderDialog.loading" :data="tenderDialog.list" border max-height="270">
          <el-table-column label="序号" type="index" width="55" align="center" />
          <el-table-column label="投标单位名称" align="center" prop="tname"  show-overflow-tooltip width="227"/>
          <el-table-column label="投标金额" align="center" prop="tprice"  show-overflow-tooltip width="180">
            <template slot-scope="scope">
              <span>{{ scope.row.tprice }} 元</span>
            </template>
          </el-table-column>
          <el-table-column label="是否中标" align="center" prop="state"  show-overflow-tooltip width="180">
            <template slot-scope="scope">
              <el-tag :type="scope.row.state === 2 ? 'danger' : 'success'">
                <dict-tag :options="dict.type.is_switch" :value="scope.row.state"/>
              </el-tag>
            </template>
          </el-table-column>
          <el-table-column label="预定标金额" align="center" show-overflow-tooltip width="232">
            <template slot-scope="scope">
              <el-input v-model="scope.row.prepareMoney" placeholder="请输入预定标金额" @input="amountChange">
                <template slot="append">元</template>
              </el-input>
            </template>
          </el-table-column>
        </el-table>
      </el-card>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="reserveOpen = false">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 查看 -->
    <el-dialog class="section-detail-dialog" :title="sectionDetail.title" :visible.sync="sectionDetail.open" width="70%" append-to-body :close-on-click-modal="false">
      <el-row>
        <el-col :span="23">
          <el-tabs type="border-card"  v-model="sectionDetail.tabName">
            <el-tab-pane label="所属项目" name="project">
              <el-form ref="sectionForm" :model="sectionDetail.projectInfo" label-width="96px">
                <el-row>
                  <el-col :span="7">
                    <el-form-item label="部门名称:">
                      <span>{{ sectionDetail.projectInfo.deptName }}</span>
                    </el-form-item>
                  </el-col>
                  <el-col :span="7" :offset="1">
                    <el-form-item label="项目编号:">
                      <span>{{ sectionDetail.projectInfo.pid }}</span>
                    </el-form-item>
                  </el-col>
                  <el-col :span="7" :offset="1">
                    <el-form-item label="项目名称:">
                      <span>{{ sectionDetail.projectInfo.pname }}</span>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="7">
                    <el-form-item label="所属板块:">
                      <span>{{ sectionDetail.projectInfo.plateName }}</span>
                    </el-form-item>
                  </el-col>
                  <el-col :span="7" :offset="1">
                    <el-form-item label="委托单位:">
                      <span>{{ sectionDetail.projectInfo.clientName }}</span>
                    </el-form-item>
                  </el-col>
                  <el-col :span="7" :offset="1">
                    <el-form-item label="资金来源:">
                      <dict-tag :options="dict.type.sys_nego_source" :value="sectionDetail.projectInfo.sourcefunds"/>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="7">
                    <el-form-item label="部门负责人:">
                      <span>{{ sectionDetail.projectInfo.leader }}</span>
                    </el-form-item>
                  </el-col>
                  <el-col :span="7" :offset="1">
                    <el-form-item label="项目负责人:">
                      <span>{{ sectionDetail.projectInfo.assistant }}</span>
                    </el-form-item>
                  </el-col>
                  <el-col :span="7" :offset="1">
                    <el-form-item label="甲方负责人:">
                      <span>{{ sectionDetail.projectInfo.jf }}</span>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="7">
                    <el-form-item label="甲方联系电话:" title="甲方联系电话">
                      <span>{{ sectionDetail.projectInfo.jfPhone }}</span>
                    </el-form-item>
                  </el-col>
                  <el-col :span="7" :offset="1">
                    <el-form-item label="备案号:">
                      <span>{{ sectionDetail.projectInfo.recordid ? sectionDetail.projectInfo.recordid : '无' }}</span>
                    </el-form-item>
                  </el-col>
                  <el-col :span="7" :offset="1">
                    <el-form-item label="备案时间:">
                      <span>{{ sectionDetail.projectInfo.recordTime ? sectionDetail.projectInfo.recordTime : '无' }}</span>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="7">
                    <el-form-item label="委托时间:">
                      <span>{{ sectionDetail.projectInfo.clientTime }}</span>
                    </el-form-item>
                  </el-col>
                  <el-col :span="7" :offset="1">
                    <el-form-item label="组织方式:">
                      <dict-tag :options="dict.type.sys_bidmethos" :value="sectionDetail.projectInfo.bidmethod"/>
                    </el-form-item>
                  </el-col>
                  <el-col :span="7" :offset="1">
                    <el-form-item label="招标类别:">
                      <dict-tag :options="dict.type.sys_bidcategory" :value="sectionDetail.projectInfo.bidcategory"/>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="7">
                    <el-form-item label="工程类别:">
                      <dict-tag v-if="sectionDetail.projectInfo.enginer" :options="dict.type.sys_enginer" :value="sectionDetail.projectInfo.enginer"/>
                      <span v-else>无</span>
                    </el-form-item>
                  </el-col>
                  <el-col :span="7" :offset="1">
                    <el-form-item label="估算金额:">
                      <span>{{ sectionDetail.projectInfo.planprice }}</span> 元
                    </el-form-item>
                  </el-col>
                  <el-col :span="7" :offset="1">
                    <el-form-item label="是否外揽:">
                      <dict-tag :options="dict.type.is_switch" :value="sectionDetail.projectInfo.decide"/>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="7">
                    <el-form-item label="是否依法:">
                      <dict-tag :options="dict.type.is_switch" :value="sectionDetail.projectInfo.law"/>
                    </el-form-item>
                  </el-col>
                  <el-col :span="7" :offset="1">
                    <el-form-item label="控制价:">
                      <span>{{ sectionDetail.projectInfo.controlprice }}</span> 元
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="23">
                    <el-form-item label="招标范围或主要技术参数:" title="招标范围或主要技术参数">
                      <span>{{ sectionDetail.projectInfo.tcpa }}</span>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="23">
                    <el-form-item label="备注:">
                      <span>{{ sectionDetail.projectInfo.remark ? sectionDetail.projectInfo.remark : '无' }}</span>
                    </el-form-item>
                  </el-col>
                </el-row>
              </el-form>
            </el-tab-pane>
            <el-tab-pane label="标段信息" name="section">
              <el-form ref="sectionForm" :model="sectionDetail.form" label-width="96px">
                <el-row>
                  <el-col :span="7">
                    <el-form-item label="招标编号:">
                      <span>{{ sectionDetail.form.sectionId }}</span>
                    </el-form-item>
                  </el-col>
                  <el-col :span="7" :offset="1">
                    <el-form-item label="招标名称:">
                      <span>{{ sectionDetail.form.sectionName }}</span>
                   </el-form-item>
                  </el-col>
                  <el-col :span="7" :offset="1">
                    <el-form-item label="组织方式:">
                      <dict-tag :options="dict.type.sys_bidmethos" :value="sectionDetail.form.bidmethod"/>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="7">
                    <el-form-item label="评标办法:">
                      <dict-tag :options="dict.type.sys_bidway" :value="sectionDetail.form.bidway"/>
                    </el-form-item>
                  </el-col>
                  <el-col :span="15" :offset="1">
                    <el-form-item label="资质设置:">
                      <span>{{ sectionDetail.form.qualify }}</span>
                   </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="7">
                    <el-form-item label="公告开始时间:" title="公告开始时间">
                      <span>{{ sectionDetail.form.annBengin }}</span>
                    </el-form-item>
                  </el-col>
                  <el-col :span="7" :offset="1">
                    <el-form-item label="公告截止时间:" title="公告截止时间">
                      <span>{{ sectionDetail.form.annEnd }}</span>
                   </el-form-item>
                  </el-col>
                  <el-col :span="7" :offset="1">
                    <el-form-item label="开标时间:">
                      <span>{{ sectionDetail.form.open }}</span>
                   </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="7">
                    <el-form-item label="开标地点:">
                      <dict-tag :options="dict.type.sys_openarea" :value="sectionDetail.form.openArea"/>
                    </el-form-item>
                  </el-col>
                  <el-col :span="7" :offset="1">
                    <el-form-item label="估算金额:">
                      <span>{{ sectionDetail.form.planprice }}</span> 元
                   </el-form-item>
                  </el-col>
                  <el-col :span="7" :offset="1">
                    <el-form-item label="是否电子标:">
                      <dict-tag :options="dict.type.is_switch" :value="sectionDetail.form.online"/>
                   </el-form-item>
                  </el-col>
                </el-row>
              </el-form>
            </el-tab-pane>
            <el-tab-pane label="投标信息" name="tender">
              <el-table :data="sectionDetail.form.tenderList" max-height="500">
                <el-table-column label="序号" type="index" width="55" align="center" />
                <el-table-column label="投标单位名称" align="center" prop="tname"  show-overflow-tooltip width="130"/>
                <el-table-column label="投标金额" align="center" prop="tprice"  show-overflow-tooltip width="140"/>
                <el-table-column label="是否中标" align="center" prop="state"  show-overflow-tooltip width="120">
                  <template slot-scope="scope">
                    <el-tag :type="scope.row.state == 2 ? 'danger' : 'success'">
                      <dict-tag :options="dict.type.is_switch" :value="scope.row.state"/>
                    </el-tag>
                  </template>
                </el-table-column>
                <el-table-column label="备注" align="center" prop="remark"  show-overflow-tooltip>
                  <template slot-scope="scope">
                    <span v-if="scope.row.remark">{{ scope.row.remark }}</span>
                    <span v-else>暂无备注</span>
                  </template>
                </el-table-column>
              </el-table>
            </el-tab-pane>
          </el-tabs>
        </el-col>
      </el-row>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="sectionDetailCancel">确 定</el-button>
        <el-button @click="sectionDetailCancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 正式定标 -->
    <el-dialog class="section-dialog" :title="reserveTitle" :visible.sync="formalOpen" width="50%" append-to-body>
      <el-card class="box-card" shadow="hover">
        <div slot="header" class="clearfix">
          <span>标段信息</span>
        </div>
        <el-form ref="formalFormRef" :model="formalForm" :rules="formalFormRules" label-width="96px">
          <el-row>
            <el-col :span="11">
              <el-form-item label="招标编号" prop="sectionId">
                <el-input v-model="formalForm.sectionId" disabled placeholder="请输入招标编号" />
              </el-form-item>
            </el-col>
            <el-col :span="11" :offset="1">
              <el-form-item label="招标名称" prop="sectionName">
                <el-input v-model="formalForm.sectionName" disabled placeholder="请输入招标名称" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="11">
              <el-form-item label="估算价" prop="planprice">
                <el-input class="pirce" v-model="formalForm.planprice" disabled placeholder="请输入估算价" /> 元
              </el-form-item>
            </el-col>
            <el-col :span="11" :offset="1">
              <el-form-item label="定标单位" prop="winCompany">
                <el-input v-model="formalForm.winCompany" disabled placeholder="请输入定标单位" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="11">
              <el-form-item label="预定标金额" prop="preMoney">
                <el-input class="pirce" v-model="formalForm.preMoney" disabled placeholder="请输入预定标金额" /> 元
              </el-form-item>
            </el-col>
            <el-col :span="11" :offset="1">
              <el-form-item label="正式定标金额" prop="formalMoney">
                <el-input class="pirce" v-model="formalForm.formalMoney" disabled placeholder="请输入定标金额" /> 元
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="11">
              <el-form-item label="正式定标时间" prop="formalDate">
                <el-date-picker clearable
                  v-model="formalForm.formalDate"
                  type="date"
                  format="yyyy-MM-dd"
                  value-format="yyyy-MM-dd"
                  placeholder="请选择正式定标时间">
                </el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </el-card>
      <el-card class="box-card" shadow="hover">
        <div slot="header" class="clearfix">
          <span>投标信息</span>
        </div>
        <el-table v-loading="tenderDialog.loading" :data="tenderDialog.list" border max-height="270">
          <el-table-column label="序号" type="index" width="55" align="center" />
          <el-table-column label="投标单位名称" align="center" prop="tname"  show-overflow-tooltip width="160"/>
          <el-table-column label="投标金额" align="center" prop="tprice"  show-overflow-tooltip width="112">
            <template slot-scope="scope">
              <span>{{ scope.row.tprice }} 元</span>
            </template>
          </el-table-column>
          <el-table-column label="是否中标" align="center" prop="state"  show-overflow-tooltip width="100">
            <template slot-scope="scope">
              <el-tag :type="scope.row.state === 2 ? 'danger' : 'success'">
                <dict-tag :options="dict.type.is_switch" :value="scope.row.state"/>
              </el-tag>
            </template>
          </el-table-column>
          <el-table-column label="预定标金额" align="center" show-overflow-tooltip width="225">
            <template slot-scope="scope">
              <el-input v-model="scope.row.prepareMoney" placeholder="请输入预定标金额" @input="amountChange('formal')">
                <template slot="append">元</template>
              </el-input>
            </template>
          </el-table-column>
          <el-table-column label="正式定标金额" align="center" show-overflow-tooltip width="225">
            <template slot-scope="scope">
              <el-input v-model="scope.row.realMoney" placeholder="请输入定标金额" @input="realMoneyChange">
                <template slot="append">元</template>
              </el-input>
            </template>
          </el-table-column>
        </el-table>
      </el-card>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFormalForm">确 定</el-button>
        <el-button @click="formalOpen = false">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import { listSection, getSection, updatePreSection, updateFormalSection } from "@/api/projectManage/sectionList";
import { listTender, updateTenderPrepare, updateTenderFormal } from "@/api/sectionManage/tender"
export default {
  name: "Section",
  dicts: ['sys_bidmethos', 'sys_openarea', 'sys_bidway', 'is_switch', 'section_progress', 'sys_bidcategory'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 标段列表表格数据
      sectionList: [],
      // 是否显示预定标
      reserveOpen: false,
      // 是否显示定标
      formalOpen: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        projectId: null,
        sectionId: null,
        sectionName: null,
        bidmethod: null,
        qualify: null,
        annBengin: null,
        annEnd: null,
        open: null,
        openArea: null,
        bidway: null,
        planprice: null,
        online: null
      },
      // 表单参数
      reserveForm: {
        preMoney: 0,
        preDate: null,
        meritDate: null,
        inn: null,
        whetherSave: null,
      },
      reserveFormRules: {
        preDate: [
          { required: true, message: '请选择预定标时间', trigger: 'blur' }
        ],
        meritDate: [
          { required: true, message: '请选择绩效确认时间', trigger: 'blur' }
        ],
        inn: [
          { required: true, message: '请选择是否内部单位中标', trigger: 'blur' }
        ],
        whetherSave: [
          { required: true, message: '请选择是否统计节支率', trigger: 'blur' }
        ]
      },
      formalForm: {
        sectionId: null,
        sectionName: null,
        winCompany: null,
        preMoney: 0,
        formalMoney: 0,
        formalDate: null
      },
      formalFormRules: {
        formalMoney: [
          { required: true, message: '请输入正式定标金额', trigger: 'blur' }
        ],
        formalDate: [
          { required: true, message: '请选择正式定标时间', trigger: 'blur' }
        ],
      },
      // 弹出层标题
      reserveTitle: '',
      // 投标信息
      tenderDialog: {
        list: [],
        loading: false,
        total: 0,
        queryParams: {
          pageNum: 1,
          pageSize: 1000,
          sid: null,
        },
      },
      // 标段详情
      sectionDetail: {
        tabName: 'project',
        open: false,
        title: '标段详情',
        form: {},
        projectInfo: {}
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询标段列表列表 */
    getList() {
      this.loading = true;
      listSection(this.queryParams).then(response => {
        this.sectionList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 表单重置
    reset() {
      this.reserveForm = {
        id: null,
        sectionId: null,
        sectionName: null,
        winCompany: null,
        preMoney: 0,
        preDate: null,
        meritDate: null,
        inn: 1,
        whetherSave: 1
      };
      this.resetForm("form");
    },
    formalReset() {
      this.formalForm = {
        id: null,
        sectionId: null,
        sectionName: null,
        winCompany: null,
        preMoney: 0,
        formalMoney: 0,
        formalDate: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/section/export', {
        ...this.queryParams
      }, `section_${new Date().getTime()}.xlsx`)
    },
    handleOpenDialog(row, flag) {
      this.tenderDialog.queryParams.sid = row.id
      getSection(row.id).then(response => {
        if (flag === 'reserve') {
          this.reset()
          this.reserveTitle = "预定标"
          response.data.preMoney = response.data.preMoney && response.data.preMoney > 0 ? response.data.preMoney : 0
          this.reserveForm.planprice = response.data.projectInfo.planprice
          this.reserveForm = response.data
          this.reserveOpen = true
        } else if (flag === 'formal') {
          this.formalReset()
          this.reserveTitle = "正式定标"
          response.data.formalMoney = response.data.formalMoney && response.data.formalMoney > 0 ? response.data.formalMoney : 0
          this.formalForm.planprice = response.data.projectInfo.planprice
          this.formalForm = response.data
          this.formalOpen = true
        }
        this.getTenderList()
      })
    },
    // 获取投标单位信息
    getTenderList() {
      this.tenderDialog.loading = true
      // 中标单位列表
      this.tenderDialog.list = []
      // 预定标金额
      let preMoney = 0
      // 正式定标金额
      let formalMoney = 0
      listTender(this.tenderDialog.queryParams).then(response => {
        response.rows.forEach(item => {
          if (item.state === 1) {
            this.tenderDialog.list.push(item)
            preMoney += item.prepareMoney ? item.prepareMoney : 0
            formalMoney += item.realMoney ? item.realMoney : 0
          }
        })
        this.$set(this.reserveForm, 'preMoney', preMoney)
        this.$set(this.formalForm, 'formalMoney', formalMoney)
        this.tenderDialog.total = response.total
        this.tenderDialog.loading = false
      })
    },
    amountChange(flag) {
      let preMoney = 0
      this.tenderDialog.list.forEach(item => {
        console.log('item.tprice', item.tprice)
        preMoney += Number(item.prepareMoney)
      })
      if (flag === 'formal') {
        this.$set(this.formalForm, 'preMoney', preMoney)
      } else {
        this.$set(this.reserveForm, 'preMoney', preMoney)
      }
    },
    realMoneyChange() {
      let realMoney = 0
      this.tenderDialog.list.forEach(item => {
        realMoney += Number(item.realMoney)
      })
      this.$set(this.formalForm, 'formalMoney', realMoney)
    },
    submitForm() {
      this.$refs['reserveFormRef'].validate(async valid => {
        if (valid) {
          const reserveForm = {
            id: this.reserveForm.id,
            preMoney: this.reserveForm.preMoney,
            preDate: this.reserveForm.preDate,
            meritDate: this.reserveForm.meritDate,
            inn: this.reserveForm.inn,
            whetherSave: this.reserveForm.whetherSave,
            winCompany: this.reserveForm.winCompany,
            sectionProgress: 4
          }
          const tenderList =  []
          this.tenderDialog.list.forEach(item => {
            tenderList.push({
              id: item.id,
              prepareMoney: item.prepareMoney
            })
          })
          try {
            const [response1, response2] = await Promise.all([
              updatePreSection(reserveForm),
              updateTenderPrepare(tenderList)
            ])
            if (response1.code === 200 && response2.code === 200) {
              this.getList()
              this.$modal.msgSuccess('预定标信息添加成功！')
            } else {
              this.$modal.msgError('正式定标信息添加失败！')
            }
          } catch {
            this.$modal.msgError('请求失败')
          }
          this.reserveOpen = false
        } else {
          this.$modal.msgWarning('请完善预定标信息！')
          return false
        }
      })
    },
    submitFormalForm() {
      debugger
      this.$refs['formalFormRef'].validate(async valid => {
        if (valid) {
          const formalForm = {
            id: this.formalForm.id,
            preMoney: this.formalForm.preMoney,
            formalMoney: this.formalForm.formalMoney,
            formalDate: this.formalForm.formalDate,
            sectionProgress: 5
          }
          const tenderList =  []
          this.tenderDialog.list.forEach(item => {
            tenderList.push({
              id: item.id,
              prepareMoney: item.prepareMoney,
              realMoney: item.realMoney
            })
          })
          try {
            const [response1, response2] = await Promise.all([
              updateFormalSection(formalForm),
              updateTenderFormal(tenderList)
            ])
            if (response1.code === 200 && response2.code === 200) {
              this.getList()
              this.$modal.msgSuccess('正式定标信息添加成功！')
            } else {
              this.$modal.msgError('正式定标信息添加失败！')
            }
          } catch {
            this.$modal.msgError('请求失败')
          }
          this.formalOpen = false
        } else {
          this.$modal.msgWarning('请完善正式定标信息！')
          return false
        }
      })
    },
    handleDetail(row) {
      getSection(row.id).then(response => {
        if (response.code == 200) {
          this.sectionDetail.form = response.data
          this.sectionDetail.projectInfo = response.data.projectInfo
          this.sectionDetail.open = true
        } else {
          this.$modal.msgError(response.msg)
        }
      })
    },
    sectionDetailCancel() {
      this.sectionDetail.tabName = 'project'
      this.sectionDetail.form = {}
      this.sectionDetail.projectInfo = {}
      this.sectionDetail.open = false
    },
    async copyText(textToCopy) {
      // navigator clipboard 需要https等安全上下文
      if (navigator.clipboard && window.isSecureContext) {
        // navigator clipboard 向剪贴板写文本
        navigator.clipboard.writeText(textToCopy).then(() => {
          this.$modal.msgSuccess('复制成功！')
        })
      } else {
        // 创建text area
        let textArea = document.createElement("textarea");
        textArea.value = textToCopy;
        // 使text area不在viewport，同时设置不可见
        textArea.style.position = "absolute";
        textArea.style.opacity = '0';
        textArea.style.left = "-999999px";
        textArea.style.top = "-999999px";
        document.body.appendChild(textArea);
        textArea.focus();
        textArea.select();
        let res = new Promise((res, rej) => {
          res(() => {
            document.execCommand('copy')
            textArea.remove();
          })
          rej(false)
        })
        res.then(res => {
          res();
          this.$modal.msgSuccess('复制成功！')
        }).catch(error => {
          this.$modal.msgError('复制失败！')
        })
      }
    }
  }
};
</script>

<style lang="scss" scoped>
::v-deep .el-dialog{
  .el-date-editor, .el-input, .el-select {
    width: 100%;
  }
  .el-dialog__body {
    padding: 30px 10px 30px 30px;
  }
  .el-form-item__label {
    max-width: 100px; /* 你可以根据需要调整这个值 */
    white-space: nowrap; /* 防止文字换行 */
    overflow: hidden; /* 超出部分隐藏 */
    text-overflow: ellipsis; /* 文字溢出时显示省略号 */
  }
  .is-disabled{
    .el-textarea__inner, .el-input__inner {
      color: #333333;
    }
    .el-radio__label {
      color: #333333;
    }
    .el-radio__inner {
      border-color: #333333;
      &::after {
        background: #333333;
      }
    }
  }
  .pirce {
    width: 94%;
  }
}
.section-dialog {
  ::v-deep .el-dialog {
    .el-dialog__body {
      padding-top: 10px;
      padding-right: 20px;
      padding-left: 20px;
      padding-bottom: 20px;
    }
    .el-card {
      margin-top: 10px;
    }
    .el-table {
      .el-table__body-wrapper {
        &::-webkit-scrollbar {
          width: 0;
        }
      }
    }
  }
}

</style>
